home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VAP2VOX.ZIP / vox2vap.c < prev   
C/C++ Source or Header  |  1994-11-06  |  2KB  |  112 lines

  1. /* VOX2VAP - Translate .VOX file to library of .VAP files 5-27-88/IHM */
  2. #include <stdio.h>
  3. #include "vapdir.h"
  4.  
  5. #define    MAXPROMPT 500
  6.  
  7. VAPDIRHDR vhdr;
  8. VAPENTRY vent[MAXPROMPT];
  9. FILE    *fp;
  10. int    prompts;
  11. char    buffah[512];
  12.  
  13. main()
  14.  
  15. {
  16. char    vapfname[40],voxpfx[40],fname[100];
  17. int    i,j,k;
  18. int    lowvox,hivox,totalvap;
  19. int    samprate = 6052;
  20. FILE    *ifp;
  21.  
  22.     printf("Enter vap file name:");
  23.     fflush(stdout);
  24.     scanf("%s",vapfname);
  25.     strcat(vapfname,".vap");
  26.     printf("Enter prefix for vox file names (use none for none) :");
  27.     fflush(stdout);
  28.     scanf("%s",voxpfx);
  29.     if (!strcmp(voxpfx,"none")) voxpfx[0] = 0;
  30.     printf("Enter low vox file number:");
  31.     fflush(stdout);
  32.     scanf("%d",&lowvox);
  33.     printf("Enter high vox file number:");
  34.     fflush(stdout);
  35.     scanf("%d",&hivox);
  36.     printf("Enter max number of prompts in VAP file:");
  37.     scanf("%d",&totalvap);
  38.  
  39.     vhdr.max_prompts = totalvap;
  40.     vhdr.sampling_rate = samprate;
  41.     prompts = vhdr.total_prompts = (hivox - lowvox) + 1;
  42.     vhdr.reserved0 = 0;
  43.     vhdr.bytes = 0;
  44.     vhdr.reserved1 = 0;
  45.  
  46.     fp = fopen(vapfname,"wb");
  47.     if (!fp)
  48.        {
  49.         perror("vap file open");
  50.         exit(255);
  51.        }        
  52.  
  53.     for(i = 0; i < MAXPROMPT; i++)
  54.        {
  55.         vent[i].start = 0;
  56.         vent[i].length = 0;
  57.         vent[i].text = 0;
  58.        }
  59.         
  60.     writedir();
  61.  
  62.     for(i = 0; i < prompts; i++)
  63.        {
  64.         sprintf(fname,"%s%d.vox",voxpfx,i + lowvox);
  65.         ifp = fopen(fname,"rb");
  66.         if (!ifp) continue;
  67.         vent[i].start = ftell(fp);
  68.         while(j = fread(buffah,1,512,ifp))
  69.            {
  70.             if (j < 0)
  71.                {
  72.                 perror("read");
  73.                 exit(255);
  74.                }
  75.             vent[i].length += j;
  76.             if (fwrite(buffah,1,j,fp) != j)
  77.                {
  78.                 perror("write");
  79.                 exit(255);
  80.                }
  81.             if (j < 512) break;
  82.            }
  83.         printf("%s, length %ld, offset %ld\n",
  84.             fname,vent[i].length,vent[i].start);
  85.         fclose(ifp);
  86.        }
  87.     
  88.     vhdr.bytes = ftell(fp);
  89.     fflush(fp);
  90.     fseek(fp,0L,0);
  91.     writedir();
  92.     fclose(fp);
  93.     exit(0);
  94. }
  95.  
  96. writedir()
  97. {
  98.  
  99.     if (fwrite(&vhdr,sizeof(vhdr),1,fp) != 1)
  100.        {
  101.         perror("header write");
  102.         exit(255);
  103.        }
  104.  
  105.     if (fwrite(vent,sizeof(VAPENTRY),prompts,fp) != prompts)
  106.        {
  107.         perror("directory write");
  108.         exit(255);
  109.        }
  110.     return(0);
  111. }
  112.